﻿using System.Collections.Generic;
using Test30.Util;
using System;

namespace Test30.Engine
{
    public abstract class ObjectPool
    {
        public static ObjectPool Get { get; private set; }
        protected Dictionary<string, List<PoolItem>> IdlePoolObjects { get; }
        protected Dictionary<PoolItem, object> WorkPoolObjects { get; }
        protected ObjectPool()
        {
            Get = this;
            IdlePoolObjects = new Dictionary<string, List<PoolItem>>();
            WorkPoolObjects = new Dictionary<PoolItem, object>();
        }

        public object Spawn(Entity entity,int depth)
        {
            string name;
            EntityType type;
            if (entity is Monster)
            {
                name = ((Character) ((Monster) entity).Race.Appearance).Glyph.ToString().RemoveSuffix(5);
                type = EntityType.Monster;
            }else if (entity is Hero)
            {
                name = ((Hero) entity).Race;
                type = EntityType.Hero;
            }
            else
            {
                throw new ArgumentOutOfRangeException();
            }
            return Get.Spawn(type, name, entity, depth);
        }
        protected abstract void CreateIdlePool();

        protected abstract void Recycle(PoolItem obj);

        protected abstract object Spawn(EntityType type,string name, Entity entity, int depth);


    }
}
